
from flask import Blueprint, request, jsonify
import os
from module.animal import Animal


UPLOAD_FOLDER = "static/uploads"
OUTPUT_FOLDER = "static/outputs"


predict_bp = Blueprint("predict", __name__)

# 定义 API 端点
@predict_bp.route('/predict', methods=['POST'])
def predict_route():
    # 获取上传的图片
    file = request.files['image']
    if file.filename == '':
        return jsonify({"error": "No selected file"}), 400


    #保存图片
    image_path = os.path.join(UPLOAD_FOLDER, file.filename)
    file.save(image_path)

    #实例化这个类
    detector = Animal()
    detector.image = image_path
    result = detector.detect_image()
    print(result)
    img_getpath = result[0].save_dir+"/"+file.filename
    return img_getpath,200

# @predict_bp.route('/predict/getimg',methods=['POST'])
# def get_detectImg():
#
#     img_path = request.files['path']
#     if img_path == "":
#         return jsonify({"error": "No path"}), 400

